
/* p5_6.c: multiple of millisecond delay using periodic mode */
/* Using Timer0B */
void timer0B_delayMs(int ttime)
{
    int i;
    SYSCTL->RCGCTIMER |= 1;     /* enable clock to Timer Block 0 */
    
    TIMER0->CTL = 0;            /* disable Timer before initialization */
    TIMER0->CFG = 0x04;         /* 16-bit option */
    TIMER0->TBMR = 0x02;        /* periodic mode and down-counter */
    TIMER0->TBILR = 16000 - 1;  /* TimerB interval load value reg */
    TIMER0->ICR = 0x100;        /* clear the TimerB timeout flag */
    TIMER0->CTL |= 0x0100;      /* enable TimerB after initialization */

    for(i = 0; i < ttime; i++)
    {
        while ((TIMER0->RIS & 0x100) == 0) ;    /* wait for TimerB timeout flag */
        TIMER0->ICR = 0x100;    /* clear the TimerB timeout flag */
    }
}
